﻿using System;
using System.Collections;
using System.Xml;

namespace InfoJetSoft.Service.Util
{
	
	public class JetIdCache
	{
		
		private System.Collections.Hashtable idTable;
		
		public JetIdCache(XmlElement xmlElement)
		{
			this.idTable = new System.Collections.Hashtable();
			this.cacheId(xmlElement);
			XmlNodeList nodeList = xmlElement.SelectNodes( ".//*" );
			foreach (XmlElement nodeElement in nodeList)
			{
				this.cacheId(nodeElement);
			}
		}
		
		public void  reset()
		{
			IEnumerator enum_Renamed = idTable.Keys.GetEnumerator();
			while (enum_Renamed.MoveNext())
			{
				XmlElement xmlElement = (XmlElement) enum_Renamed.Current;
				XmlAttribute idAttr = (XmlAttribute) this.idTable[xmlElement];
				xmlElement.SetAttributeNode(idAttr);
			}
		}
		
		private void  cacheId(XmlElement xmlElement)
		{
			XmlAttribute idAttr = (XmlAttribute) xmlElement.GetAttributeNode(JetConstant.JetId);
			if (idAttr != null)
			{
				idTable.Add(xmlElement, idAttr);
				xmlElement.RemoveAttributeNode(idAttr);
			}
		}
	}
}